package cz.edukomplex.kosilka.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.event.logical.shared.SelectionEvent;
import com.google.gwt.event.logical.shared.SelectionHandler;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.DecoratedTabBar;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.LayoutPanel;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

import cz.edukomplex.kosilka.client.content.block.BlockContent;
import cz.edukomplex.kosilka.client.content.harmonogram.HarmonogramContent;
import cz.edukomplex.kosilka.client.content.result.ResultContent;

public class KosilkaV3 implements EntryPoint {

	private static KosilkaV3UiBinder uiBinder = GWT
			.create(KosilkaV3UiBinder.class);

	interface KosilkaV3UiBinder extends UiBinder<Widget, KosilkaV3> {
	}
		
	private static final int TAB_SUBJECT = 0;
	private static final int TAB_HARMONOGRAM = 1;
	private static final int TAB_RESULT = 2;
		
	@UiField HeaderPanel headerPanel;
	@UiField DecoratedTabBar menuTabBar;
	
	/*
	@UiField
	public SouthPanel southPanel;
	*/
	
	@UiField DockLayoutPanel contentWrapper;
		
		
	@Override
	public void onModuleLoad() {
		final DockLayoutPanel container = (DockLayoutPanel) uiBinder.createAndBindUi(this);			
		RootLayoutPanel.get().add(container);
		initMenu();
		
		setContent(new HarmonogramContent());		
	}
		
	private void initMenu(){
		menuTabBar.addTab("Predmety");
		menuTabBar.addTab("Harmonogramy");
		menuTabBar.addTab("Výsledky");
		
		menuTabBar.addSelectionHandler(new SelectionHandler<Integer>() {
			
			@Override
			public void onSelection(SelectionEvent<Integer> event) {
				switch (event.getSelectedItem()) {
				case TAB_HARMONOGRAM:
					setContent(new HarmonogramContent());
					break;
				case TAB_SUBJECT:
					setContent(new BlockContent());
					break;
				case TAB_RESULT:
					setContent(new ResultContent());
					break;
				default:
					break;
				}
				
			}
		});
		
	}
	
	/**
	 * Nastavi obsah stranky
	 * 
	 * @param content
	 */
	protected void setContent(Widget content){
		if(content == null){			
			contentWrapper.clear();
			contentWrapper.add(new HTML("&nbsp;"));
		}
		else{			
			contentWrapper.clear();
			contentWrapper.add(content);
		}
	}	
}